package com.leoman.post.dao;

import com.leoman.common.dao.IBaseJpaRepository;
import com.leoman.post.entity.PostBase;
import com.leoman.post.entity.PostTypeData;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

/**
 * 帖子分类dao
 * Created by 涂奕恒 on 2016/12/14.
 */
public interface PostTypeDataDao extends IBaseJpaRepository<PostTypeData> {

    @Query("select a from PostTypeData a where a.category.id = ?1 and a.createDate = ?2")
    PostTypeData findOneByCategoryIdAndCreateDate(Long categoryId, String createDate);

    @Query("select a from PostTypeData a where a.category.type = 1 and a.category.name like ?1 and a.createDate = ?2 group by a.category.id")
    Page<PostTypeData> pageByParams(String typeName, String createDate, Pageable pageable);

    @Query("select a from PostTypeData a where a.category.type = 1 group by a.category.id")
    Page<PostTypeData> pageByParams(Pageable pageable);

    @Query("select a from PostTypeData a where a.category.id = ?1")
    List<PostTypeData> findListByCategoryId(Long categoryId);

    @Query("select a from PostBase a where a.category.id = ?1 and a.deleteStatus <> 1")
    List<PostBase> findPostBaseListByCategoryId(Long categoryId);

    @Query("select a from PostTypeData a where a.category.id = ?1 and a.createDate >= ?2 and a.createDate <= ?3 order by a.createDate desc")
    Page<PostTypeData> pageByCategoryId(Long categoryId, String startDate, String endDate, Pageable pageable);
}
